*** ANES Cumulative Data File, 1948-2012

use "anes_timeseries_cdf.dta"


********************************************************************************

*** Recoding IVs, controls, and other items ***

* Create ID and year identifiers
gen caseid = VCF0006
gen year = VCF0004
gen sample = 1


* Survey weights
gen weight = VCF0009x


* Survey mode
gen svymode = VCF0017
drop if svymode == 4
	
	
* Self ideology (recoded to range -3-3; -2 Havent thought, -8 DK, -9 NA)
gen ideo = VCF0803
replace ideo = . if ideo < 1 
replace ideo = . if ideo == 9 
recode ideo (1=-3) (2=-2) (3=-1) (4=0) (5=1) (6=2) (7=3)

gen conserv = 1 if ideo > 0 & ideo < 4
replace conserv = 0 if ideo < 0


* Strength of ideological predisposition
gen ideostrength = 0 if ideo == 0
replace ideostrength = 1 if ideo == -1
replace ideostrength = 1 if ideo == 1
replace ideostrength = 2 if ideo == -2
replace ideostrength = 2 if ideo == 2
replace ideostrength = 3 if ideo == -3
replace ideostrength = 3 if ideo == -3


* Self party ID (recoded to range -3-3; -2 DK NA)
gen pid = VCF0301 
replace pid = . if pid == 0
recode pid (1=-3) (2=-2) (3=-1) (4=0) (5=1) (6=2) (7=3)

gen rep = 1 if pid > 0 & pid < 4
replace rep = 0 if pid < 0


* Strength of ideological predisposition
gen pidstrength = 0 if pid == 0
replace pidstrength = 1 if pid == -1
replace pidstrength = 1 if pid == 1
replace pidstrength = 2 if pid == -2
replace pidstrength = 2 if pid == 2
replace pidstrength = 3 if pid == -3
replace pidstrength = 3 if pid == -3


* Education (ranges from 1-7)
gen edu = VCF0140a
replace edu = . if edu >= 8
label define edulab 1 "8 grades or less" 2 "9-12 grades" 3 "High school" ///
	4 "HS + non-academic training" 5 "Some college" 6 "BA" 7 "Advanced"
label values edu edulab


* Race 
gen race = VCF0105a
replace race = . if race == 9

gen black = 1 if race == 2
replace black = 0 if race != 2 & race != .

gen hispanic = 1 if race == 5
replace hispanic = 0 if race != 5 & race != .


* Gender (1=female)
gen gender = VCF0104
replace gender = . if gender < 1
gen female = 1 if gender == 2
recode female (.=0)
label define genderlab 0 "Male" 1 "Female"
label values female genderlab


* Age (number of years) 
gen age = VCF0101
replace age = . if age == 00


* Region
gen south = .
replace south = 0 if VCF0112 == 1
replace south = 0 if VCF0112 == 2
replace south = 0 if VCF0112 == 4
replace south = 1 if VCF0112 == 3
label var south "South Region Dummy"
label define southern 0 "0 Non-South" 1 "1 South"
label values south southern


* Income
gen income = VCF0114 - 1
replace income = . if income < 0


* Religiosity
gen religiosity = VCF0130
recode religiosity (0=.) (7=.) (8=.) (9=.) (5=0) (4=1) (3=2) (2=3) (1=4)

 
* Number of party likes/dislikes (0 - 5 likes)
gen demlike = VCF0314
replace demlike = . if demlike == 9

gen demdislike = VCF0315
replace demdislike = . if demdislike == 9

gen replike = VCF0318
replace replike = . if replike == 9

gen repdislike = VCF0319
replace repdislike = . if repdislike == 9


* Feeling thermometers
gen liberaltherm = VCF0211
replace liberaltherm = . if liberaltherm >= 98
gen conservtherm = VCF0212
replace conservtherm = . if conservtherm >= 98
gen ideothermdiff = abs(liberaltherm - conservtherm)


gen dempartytherm = VCF0218
replace dempartytherm = . if dempartytherm >= 98
gen reppartytherm = VCF0224
replace reppartytherm = . if reppartytherm >= 98
gen partydifftherm = abs(dempartytherm - reppartytherm)


gen demcandtherm = VCF0424
replace demcandtherm = . if demcandtherm >= 98
gen repcandtherm = VCF0426
replace repcandtherm = . if repcandtherm >= 98
gen diffcandtherm = abs(demcandtherm - repcandtherm)


* Party placement on ideological scale
gen demideo = VCF0503
replace demideo = . if demideo == 0
replace demideo = . if demideo == 8

gen repideo = VCF0504
replace repideo = . if repideo == 0
replace repideo = . if repideo == 8

gen partyideodiff = abs(demideo - repideo)


* Candidate placement on ideological scale
gen dcandideo = VCF9088
replace dcandideo = . if dcandideo == 0
replace dcandideo = . if dcandideo >= 8

gen rcandideo = VCF9089
replace rcandideo = . if rcandideo == 0
replace rcandideo = . if rcandideo >= 8

gen candideodiff = abs(dcandideo - rcandideo)


* Sorting
gen sorting = abs(ideo - (-1*pid)) * (ideostrength * pidstrength)


* Placement on guaranteed jobs scale 
gen selfjobs = VCF0809
replace selfjobs = . if selfjobs == 0
replace selfjobs = . if selfjobs >= 8
label values selfjobs jobslab

gen demjobs = VCF0513
replace demjobs = . if demjobs == 0
replace demjobs = . if demjobs >= 8
label values demjobs jobslab

gen repjobs = VCF0514
replace repjobs = . if repjobs == 0
replace repjobs = . if repjobs >= 8
label values repjobs jobslab

gen pdiffjobs = abs(demjobs - repjobs)


* Self placement on aid to blacks scale 
gen selfaid = VCF0830
replace selfaid = . if selfaid == 0
replace selfaid = . if selfaid >= 8
label values selfaid aidlab


* Party placement on aid to blacks scale 
gen demaid = VCF0517
replace demaid = . if demaid == 0
replace demaid = . if demaid >= 8
label values demaid aidlab

gen repaid = VCF0518
replace repaid = . if repaid == 0
replace repaid = . if repaid >= 8
label values repaid aidlab

gen pdiffaid = abs(demaid - repaid)


* Self placement on government services scale 
gen selfservice = VCF0839
replace selfservice = . if selfservice == 0
replace selfservice = . if selfservice >= 8
recode selfservice (1=7) (2=6) (3=5) (4=4) (5=3) (6=2) (7=1)


* Party placement on government services scale 
gen demservice = VCF0541
replace demservice = . if demservice == 0
replace demservice = . if demservice >= 8
recode demservice (1=7) (2=6) (3=5) (4=4) (5=3) (6=2) (7=1)

gen repservice = VCF0542
replace repservice = . if repservice == 0
replace repservice = . if repservice >= 8
recode repservice (1=7) (2=6) (3=5) (4=4) (5=3) (6=2) (7=1)

gen pdiffservice = abs(demservice - repservice)


* Self placement on defense spending scale 
gen selfdefense = VCF0843
replace selfdefense = . if selfdefense == 0
replace selfdefense = . if selfdefense >= 8


* Party placement on defense spending scale 
gen demdefense = VCF0549
replace demdefense = . if demdefense == 0
replace demdefense = . if demdefense >= 8

gen repdefense = VCF0550
replace repdefense = . if repdefense == 0
replace repdefense = . if repdefense >= 8

gen pdiffdefense = abs(demdefense - repdefense)


* Self placement on government health insurance scale
gen selfinsure = VCF0806
replace selfinsure = . if selfinsure == 0
replace selfinsure = . if selfinsure == 9


* Party placement on government health insurance scale
gen deminsure = VCF0508
replace deminsure = . if deminsure == 0
replace deminsure = . if deminsure >= 8

gen repinsure = VCF0509
replace repinsure = . if repinsure == 0
replace repinsure = . if repinsure >= 8

gen pdiffinsure = abs(deminsure - repinsure)


* Self placement on abortion scale
gen selfabort = VCF0806
replace selfabort = . if selfabort < 1
replace selfabort = . if selfabort > 4
label define abortlab 1 "Never be permitted" 4 "Always permitted"
label values selfabort abortlab


* Do whatever is necessary for equal opportunity
* Note: This variable is reverse coded so that higher values indicate
* more conservative attitudes
gen equalopp = VCF9013 - 1
replace equalopp = . if equalopp > 4
label define equalopportunity 0 "0 Agree strongly" 1 "1 Agree somewhat" ///
	2 "2 Neither agree nor disagree" 3 "3 Disagree somewhat" ///
	4 "4 Disagree strongly"
label values equalopp equalopportunity


* Have gone too far pushing equal rights
* Note: This variable is reverse coded so that higher values indicate
* more conservative attitudes
gen equalrights = VCF9014
replace equalrights = . if equalrights > 5
recode equalrights (5=0) (4=1) (3=2) (2=3) (1=4)
label define equalrightspush 0 "0 Disagree strongly" 1 "1 Disagree somewhat" /// 
	2 "2 Neither agree nor disagree" 3 "3 Agree somewhat" 4 "4 Agree strongly"
label values equalrights equalrightspush


* Big problem is not giving everyone an equal chance*
gen equalchance = VCF9015 - 1
replace equalchance = . if equalchance > 4
label define equalchances 0 "0 Agree strongly" 1 "1 Agree somewhat" ///
	2 "2 Neither agree nor disagree" 3 "3 Disagree somewhat" ///
	4 "4 Disagree strongly"
label values equalchance equalchances


* Better off if we worried less about equality
* Note: This variable is reverse coded so that higher values indicate
* more conservative attitudes
gen lessequal = VCF9017
replace lessequal = . if lessequal > 5
recode lessequal (5=0) (4=1) (3=2) (2=3) (1=4)
label define lessequality 0 "0 Disagree strongly" 1 "1 Disagree somewhat" /// 
	2 "2 Neither agree nor disagree" 3 "3 Agree somewhat" 4 "4 Agree strongly"
label values lessequal lessequality


* Not that big of a problem if people have more of a chance
* Note: This variable is reverse coded so that higher values indicate
* more conservative attitudes ???????
gen unequal = VCF9016
replace unequal = . if unequal > 5
recode unequal (5=0) (4=1) (3=2) (2=3) (1=4)
label define unequalchance 0 "0 Disagree strongly" 1 "1 Disagree somewhat" ///
	2 "2 Neither agree nor disagree" 3 "3 Agree somewhat" 4 "4 Agree strongly"
label values unequal unequalchance


* Many fewer problems if people were treated equally
gen fewer = VCF9018 - 1
replace fewer = . if fewer > 4
label define fewerproblems 0 "0 Agree strongly" 1 "1 Agree somewhat" ///
	2 "2 Neither agree nor disagree" 3 "3 Disagree somewhat" ///
	4 "4 Disagree strongly"
label values fewer fewerproblems


* Adjusting views of moral behavior
gen changing = VCF0852 - 1
replace changing = . if changing > 4
label define changingmorals 0 "Agree strongly" 1 "Agree somewhat" ///
	2 "Neither agree nor disagree" 3 "Disagree somewhat" 4 "Disagree strongly"
label values changing changingmorals
 
 
* Newer lifestyles contributing to a breakdown in society
* Note: This variable is reverse coded so that higher values indicate*
* more conservative attitudes
gen lifestyles = VCF0851
replace lifestyles = . if lifestyles > 5
recode lifestyles (5=0) (4=1) (3=2) (2=3) (1=4)
label define lifestylesnew 0 "0 Disagree strongly" 1 "1 Disagree somewhat" /// 
	2 "2 Neither agree nor disagree"  3 "3 Agree somewhat" 4 "4 Agree strongly"
label values lifestyles lifestylesnew


* Tolerant of people who choose to live according to their own moral standards
gen standards = VCF0854 - 1
replace standards = . if standards > 4
label define standardsown 0 "0 Agree strongly" 1 "1 Agree somewhat" ///
	2 "2 Neither agree nor disagree" 3 "3 Disagree somewhat" ///
	4 "4 Disagree strongly"
label values standards standardsown
 
 
* More emphasis on traditional family ties*
* Note: This variable is reverse coded so that higher values indicate
* more conservative attitudes
gen family = VCF0853
replace family = . if family > 5
recode family (5=0) (4=1) (3=2) (2=3) (1=4)
label define familyties 0 "0 Disagree strongly" 1 "1 Disagree somewhat" /// 
	2 "2 Neither agree nor disagree"  3 "3 Agree somewhat" 4 "4 Agree strongly"
label values family familyties


* Creating values scales
alpha equalopp equalrights equalchance lessequal unequal fewer changing ///
	lifestyles standards family, detail item generate(values) casewise

alpha equalopp equalrights equalchance lessequal unequal fewer, ///
	detail item generate(equality) casewise

alpha changing lifestyles standards family, detail item ///
	generate(morality) casewise
	
gen valuediff = equality - morality	
gen absvaluediff = abs(valuediff)


* Value "polarization", or extremity
gen valuepold = .
gen valuepolr = .	
	
levelsof year, local(lev)	
	
foreach i of local lev {
sum values if values != . & rep == 1 & year == `i', meanonly
replace valuepold = values - r(mean) if values != . & rep == 0 & year == `i'
sum values if values != . & rep == 0 & year == `i', meanonly
replace valuepolr = values - r(mean) if values != . & rep == 1 & year == `i'
}

replace valuepold = abs(valuepold)
replace valuepolr = abs(valuepolr)
egen valuepol = rowmax(valuepold valuepolr)


* Vote choice
gen prezvote = VCF0704
replace prezvote = . if prezvote == 0
label define prezvotelab 1 "Democrat" 2 "Republican" 3 "Third party"
label values prez prezvotelab

gen votedum = prezvote - 1
replace votedum = . if votedum == 2

gen yesvote = VCF0702 - 1
replace yesvote = . if yesvote < 0 | yesvote > 1

gen congvote = VCF0707
replace congvote = . if congvote == 0
label define votelab 1 "Democrat" 2 "Republican"
label values congvote votelab

gen senvote = VCF0708
replace senvote = . if senvote == 0
label values senvote votelab


* Level of information, as assessed by interviewer
gen info = VCF0050a
replace info = . if info == 9
recode info (1=5) (2=4) (3=3) (4=2) (1=5)
label define infolab 1 "Very low" 2 "Fairly Low" 3 "Average" ///
	4 "Fairly High" 5 "Very High"
label values info infolab


* Interest in campaigns (1 Hardly at all - 4 Most of the time)
gen interest = VCF0310
replace interest = . if VCF0310 == 0
replace interest = . if VCF0310 == 9
label var interest "Interest in the the Campaigns"
label define interestlab 1 "Not much interested" ///
	2 "Somewhat interested" 3 "Very much interested"
label values interest interestlab


* External efficacy index (0 Least efficacious - 100 Most efficacious)
gen efficacy = VCF0648
replace efficacy = . if efficacy == 999


* Trust in government index (0 Least trusting - 100 Most trusting)
gen trust = VCF0656
replace trust = . if trust == 999


* Participation index (1 Lowest - 6 Highest)
gen participate = VCF0723
replace participate = . if participate == 0


* Media exposure index (1 No media - 5 All four media)
gen media = VCF0728
replace media = . if media == 0


* Sophistication scale
factor info interest participate, factor(1) ipf
predict sophscale1

factor interest participate if year == 1978, factor(1) ipf
predict sophscale2

factor interest participate if year == 1982, factor(1) ipf
predict sophscale3

factor interest participate if year == 1990, factor(1) ipf
predict sophscale4

factor interest participate if year == 1994, factor(1) ipf
predict sophscale5

egen sophistication = rowmax(sophscale*)


* Elite polarization
gen housepol = 0.492 if year == 1972
replace housepol = 0.499 if year == 1976
replace housepol = 0.489 if year == 1978
replace housepol = 0.514 if year == 1980
replace housepol = 0.540 if year == 1982
replace housepol = 0.573 if year == 1984
replace housepol = 0.618 if year == 1988
replace housepol = 0.634 if year == 1990
replace housepol = 0.664 if year == 1992
replace housepol = 0.727 if year == 1994
replace housepol = 0.818 if year == 1996
replace housepol = 0.877 if year == 2000
replace housepol = 0.942 if year == 2004
replace housepol = 1.091 if year == 2012


keep caseid-housepol


********************************************************************************

* Constrained CFA of perceived polarization variables	
	
drop if year < 1972	
*drop if year == 1974 | year == 1986 | year == 1998 | year == 2002 
	
egen yearalt = group(year)
replace yearalt = yearalt - 1	
	
* Use 1972 to calibrate "partyideodiff"

factor partyideodiff pdiffjobs pdiffaid pdiffinsure if year == 1972, ipf
sem (Polarize -> partyideodiff pdiffjobs pdiffaid pdiffinsure  ///
	if year == 1972)
predict ppolscore1972, latent		

constraint 1 _b[partyideodiff:Polarize] = 1
*constraint 2 _b[partyideodiff:_cons] =  2.277487


* 1976
factor partyideodiff pdiffjobs pdiffaid pdiffinsure if year == 1976, ipf
sem (Polarize -> partyideodiff pdiffjobs pdiffaid pdiffinsure ///
	if year == 1976), constraints(1) standard
predict ppolscore1976, latent	


* 1978
factor pdiffjobs pdiffaid pdiffinsure partyideodiff if year == 1978, ipf
sem (Polarize -> pdiffjobs pdiffaid pdiffinsure partyideodiff ///
	if year == 1978), constraints(1) standard
predict ppolscore1978, latent	


* 1980
factor pdiffjobs pdiffaid pdiffdefense partyideodiff candideodiff ///
	if year == 1980, ipf
sem (Polarize -> pdiffjobs pdiffaid pdiffdefense partyideodiff candideodiff ///
	if year == 1980), constraints(1) standard
predict ppolscore1980, latent


* 1982
factor pdiffjobs pdiffaid pdiffservice pdiffdefense partyideodiff ///
	if year == 1982, ipf
sem (Polarize -> pdiffjobs pdiffaid pdiffservice pdiffdefense partyideodiff ///
	if year == 1982), constraints(1) standard
predict ppolscore1982, latent


* 1984
factor pdiffjobs pdiffaid pdiffservice pdiffdefense partyideodiff ///
	candideodiff if year == 1984, ipf
sem (Polarize -> pdiffjobs pdiffaid pdiffservice pdiffdefense partyideodiff ///
	candideodiff if year == 1984), constraints(1) standard
predict ppolscore1984, latent


* 1988
factor pdiffjobs pdiffaid pdiffservice pdiffdefense pdiffinsure ///
	partyideodiff candideodiff if year == 1988, ipf
sem (Polarize -> pdiffjobs pdiffaid pdiffservice pdiffdefense pdiffinsure ///
	partyideodiff candideodiff if year == 1988), constraints(1) standard
predict ppolscore1988, latent


* 1990
factor pdiffaid pdiffservice pdiffdefense partyideodiff ///
	if year == 1990, ipf
sem (Polarize -> pdiffaid pdiffservice pdiffdefense partyideodiff ///
	if year == 1990), constraints(1) standard
predict ppolscore1990, latent


* 1992
factor pdiffjobs pdiffservice pdiffdefense partyideodiff ///
	candideodiff if year == 1992, ipf
sem (Polarize -> pdiffjobs pdiffservice pdiffdefense partyideodiff ///
	candideodiff if year == 1992), constraints(1) standard
predict ppolscore1992, latent


* 1994
factor pdiffjobs pdiffaid pdiffservice pdiffinsure partyideodiff ///
	if year == 1994, ipf
sem (Polarize -> pdiffjobs pdiffaid pdiffservice pdiffinsure partyideodiff ///
	if year == 1994), constraints(1) standard
predict ppolscore1994, latent


* 1996
factor pdiffservice pdiffdefense partyideodiff candideodiff ///
	if year == 1996, ipf
sem (Polarize ->  pdiffservice pdiffdefense partyideodiff candideodiff ///
	if year == 1996), constraints(1) standard
predict ppolscore1996, latent


* 2000
factor pdiffjobs pdiffaid pdiffservice pdiffdefense partyideodiff ///
	candideodiff if year == 2000, ipf
sem (Polarize -> pdiffjobs pdiffaid pdiffservice pdiffdefense partyideodiff ///
	candideodiff if year == 2000), constraints(1) standard
predict ppolscore2000, latent


* 2004
factor pdiffjobs pdiffaid pdiffservice pdiffdefense partyideodiff ///
	candideodiff if year == 2004, ipf
sem (Polarize -> pdiffjobs pdiffaid pdiffservice pdiffdefense partyideodiff ///
	candideodiff if year == 2004), constraints(1) standard
predict ppolscore2004, latent


* 2012
factor pdiffjobs pdiffservice pdiffdefense pdiffinsure ///
	partyideodiff candideodiff if year == 2012, ipf
sem (Polarize -> pdiffjobs pdiffservice pdiffdefense pdiffinsure ///
	partyideodiff candideodiff if year == 2012), constraints(1) standard
predict ppolscore2012, latent


gen ppolscore = .
replace ppolscore = ppolscore1972 if year == 1972
replace ppolscore = ppolscore1976 if year == 1976
replace ppolscore = ppolscore1978 if year == 1978
replace ppolscore = ppolscore1980 if year == 1980
replace ppolscore = ppolscore1982 if year == 1982
replace ppolscore = ppolscore1984 if year == 1984
replace ppolscore = ppolscore1988 if year == 1988
replace ppolscore = ppolscore1990 if year == 1990
replace ppolscore = ppolscore1992 if year == 1992
replace ppolscore = ppolscore1994 if year == 1994
replace ppolscore = ppolscore1996 if year == 1996
replace ppolscore = ppolscore2000 if year == 2000
replace ppolscore = ppolscore2004 if year == 2004
replace ppolscore = ppolscore2012 if year == 2012







gen pdiffpideo2 = .
gen pdiffcideo2 = .
gen pdiffaid2 = .
gen pdiffjobs2 = .
gen pdiffdefense2 = .
gen pdiffservice2 = .
gen pdiffinsure2 = .

replace ideo = ideo + 4

levelsof year, local(lev)	
	
foreach i of local lev {
replace pdiffpideo2 = abs(ideo - repideo) if rep == 0 & ideo != . & year == `i'
replace pdiffpideo2 = abs(ideo - demideo) if rep == 1 & ideo != . & year == `i'

replace pdiffcideo2 = abs(ideo - rcandideo) if rep == 0 & ideo != . & year == `i'
replace pdiffcideo2 = abs(ideo - dcandideo) if rep == 1 & ideo != . & year == `i'

replace pdiffaid2 = abs(selfaid - repaid) if rep == 0 & selfaid != . & year == `i'
replace pdiffaid2 = abs(selfaid - demaid) if rep == 1 & selfaid != . & year == `i'

replace pdiffjobs2 = abs(selfjobs - repjobs) if rep == 0 & selfjobs != . & year == `i'
replace pdiffjobs2 = abs(selfjobs - demjobs) if rep == 1 & selfjobs != . & year == `i'

replace pdiffdefense2 = abs(selfdefense - repdefense) if rep == 0 & selfdefense != . & year == `i'
replace pdiffdefense2 = abs(selfdefense - demdefense) if rep == 1 & selfdefense != . & year == `i'

replace pdiffservice2 = abs(selfservice - repservice) if rep == 0 & selfservice != . & year == `i'
replace pdiffservice2 = abs(selfservice - demservice) if rep == 1 & selfservice != . & year == `i'

replace pdiffinsure2 = abs(selfinsure - repinsure) if rep == 0 & selfinsure != . & year == `i'
replace pdiffinsure2 = abs(selfinsure - deminsure) if rep == 1 & selfinsure != . & year == `i'
}


* 1972
factor pdiffpideo2 pdiffcideo2 pdiffjobs2 pdiffaid2 ///
	pdiffinsure2 if year == 1972, ipf
sem (Polarize -> pdiffpideo2 pdiffcideo2 pdiffjobs2 pdiffaid2 ///
	pdiffinsure2 if year == 1972)
predict ppolscore1972b, latent		

constraint 1 _b[pdiffpideo2:Polarize] = 1
constraint 2 _b[pdiffpideo2:_cons] = 2.227586

* 1976
factor pdiffpideo2 pdiffjobs2 pdiffaid2 pdiffinsure2 ///
	if year == 1976, ipf
sem (Polarize -> pdiffpideo2 pdiffjobs2 pdiffaid2 pdiffinsure2 ///
	if year == 1976), constraints(1/2) standard
predict ppolscore1976b, latent			
	
* 1978	
factor pdiffjobs2 pdiffaid2 pdiffinsure2 pdiffpideo2 ///
	if year == 1978, ipf
sem (Polarize -> pdiffjobs2 pdiffaid2 pdiffinsure2 pdiffpideo2 ///
	if year == 1978), constraints(1/2) standard
predict ppolscore1978b, latent			

* 1980
factor pdiffjobs2 pdiffaid2 pdiffdefense2 pdiffpideo2 pdiffcideo2 ///
	if year == 1980, ipf
sem (Polarize -> pdiffjobs2 pdiffaid2 pdiffdefense2 pdiffpideo2 pdiffcideo2 ///
	if year == 1980), constraints(1/2) standard
predict ppolscore1980b, latent		

* 1982
factor pdiffjobs2 pdiffaid2 pdiffservice2 pdiffdefense2 pdiffpideo2 ///
	if year == 1982, ipf
sem (Polarize -> pdiffjobs2 pdiffaid2 pdiffservice2 pdiffdefense2 pdiffpideo2 ///
	if year == 1982), constraints(1/2) standard
predict ppolscore1982b, latent

* 1984
factor pdiffjobs2 pdiffaid2 pdiffservice2 pdiffdefense2 pdiffpideo2 ///
	pdiffcideo2 if year == 1984, ipf
sem (Polarize -> pdiffjobs2 pdiffaid2 pdiffservice2 pdiffdefense2 pdiffpideo2 ///
	pdiffcideo2 if year == 1984), constraints(1/2) standard
predict ppolscore1984b, latent

* 1988
factor pdiffjobs2 pdiffaid2 pdiffservice2 pdiffdefense2 pdiffinsure2 ///
	pdiffpideo2 pdiffcideo2 if year == 1988, ipf
sem (Polarize -> pdiffjobs2 pdiffaid2 pdiffservice2 pdiffdefense2 pdiffinsure2 ///
	pdiffpideo2 pdiffcideo2 if year == 1988), constraints(1/2) standard
predict ppolscore1988b, latent

* 1990
factor pdiffaid2 pdiffservice2 pdiffdefense2 pdiffpideo2 ///
	if year == 1990, ipf
sem (Polarize -> pdiffaid2 pdiffservice2 pdiffdefense2 pdiffpideo2 ///
	if year == 1990), constraints(1/2) standard
predict ppolscore1990b, latent

* 1992
factor pdiffjobs2 pdiffservice2 pdiffdefense2 pdiffpideo2 ///
	pdiffcideo2 if year == 1992, ipf
sem (Polarize -> pdiffjobs2 pdiffservice2 pdiffdefense2 pdiffpideo2 ///
	pdiffcideo2 if year == 1992), constraints(1/2) standard
predict ppolscore1992b, latent
	
* 1994	
factor pdiffjobs2 pdiffaid2 pdiffservice2 pdiffinsure2 pdiffpideo2 ///
	if year == 1994, ipf
sem (Polarize -> pdiffjobs2 pdiffaid2 pdiffservice2 pdiffinsure2 pdiffpideo2 ///
	if year == 1994), constraints(1/2) standard
predict ppolscore1994b, latent

* 1996
factor pdiffservice2 pdiffdefense2 pdiffpideo2 pdiffcideo2 ///
	if year == 1996, ipf
sem (Polarize ->  pdiffservice2 pdiffdefense2 pdiffpideo2 pdiffcideo2 ///
	if year == 1996), constraints(1/2) standard
predict ppolscore1996b, latent

* 2000
factor pdiffjobs2 pdiffaid2 pdiffservice2 pdiffdefense2 pdiffpideo2 ///
	pdiffcideo2 if year == 2000, ipf
sem (Polarize -> pdiffjobs2 pdiffaid2 pdiffservice2 pdiffdefense2 pdiffpideo2 ///
	pdiffcideo2 if year == 2000), constraints(1/2) standard
predict ppolscore2000b, latent

* 2004
factor pdiffjobs2 pdiffaid2 pdiffservice2 pdiffdefense2 pdiffpideo2 ///
	pdiffcideo2 if year == 2004, ipf
sem (Polarize -> pdiffjobs2 pdiffaid2 pdiffservice2 pdiffdefense2 pdiffpideo2 ///
	pdiffcideo2 if year == 2004), constraints(1/2) standard
predict ppolscore2004b, latent

* 2012
factor pdiffjobs2 pdiffservice2 pdiffdefense2 pdiffinsure2 ///
	pdiffpideo2 pdiffcideo2 if year == 2012, ipf
sem (Polarize -> pdiffjobs2 pdiffservice2 pdiffdefense2 pdiffinsure2 ///
	pdiffpideo2 pdiffcideo2 if year == 2012), constraints(1/2) standard
predict ppolscore2012b, latent


gen ppolscoreb = .
replace ppolscoreb = ppolscore1972b if year == 1972
replace ppolscoreb = ppolscore1976b if year == 1976
replace ppolscoreb = ppolscore1978b if year == 1978
replace ppolscoreb = ppolscore1980b if year == 1980
replace ppolscoreb = ppolscore1982b if year == 1982
replace ppolscoreb = ppolscore1984b if year == 1984
replace ppolscoreb = ppolscore1988b if year == 1988
replace ppolscoreb = ppolscore1990b if year == 1990
replace ppolscoreb = ppolscore1992b if year == 1992
replace ppolscoreb = ppolscore1994b if year == 1994
replace ppolscoreb = ppolscore1996b if year == 1996
replace ppolscoreb = ppolscore2000b if year == 2000
replace ppolscoreb = ppolscore2004b if year == 2004
replace ppolscoreb = ppolscore2012b if year == 2012


********************************************************************************

* "Actual" individual level polarization

gen adiffideo = .
gen adiffaid = .
gen adiffjobs = .
gen adiffdefense = .
gen adiffservice = .
gen adiffinsure = .

levelsof year, local(lev)	
	
foreach i of local lev {
sum ideo if rep == 1 & ideo != . & year == `i', meanonly
replace adiffideo = ideo - r(mean) if rep == 0 & ideo != . & year == `i'
sum ideo if rep == 0 & ideo != . & year == `i', meanonly
replace adiffideo = ideo - r(mean) if rep == 1 & ideo != . & year == `i'

sum ideo if rep == 1 & ideo != . & year == `i', meanonly
replace adiffideo = ideo - r(mean) if rep == 0 & ideo != . & year == `i'
sum ideo if rep == 0 & ideo != . & year == `i', meanonly
replace adiffideo = ideo - r(mean) if rep == 1 & ideo != . & year == `i'

sum selfaid if rep == 1 & selfaid != . & year == `i', meanonly
replace adiffaid = selfaid - r(mean) if rep == 0 & selfaid != . & year == `i'
sum selfaid if rep == 0 & selfaid != . & year == `i', meanonly
replace adiffaid = selfaid - r(mean) if rep == 1 & selfaid != . & year == `i'

sum selfservice if rep == 1 & selfservice != . & year == `i', meanonly
replace adiffservice = selfservice - r(mean) if rep == 0 & selfservice != . & year == `i'
sum selfservice if rep == 0 & selfservice != . & year == `i', meanonly
replace adiffservice = selfservice - r(mean) if rep == 1 & selfservice != . & year == `i'

sum selfjobs if rep == 1 & selfjobs != . & year == `i', meanonly
replace adiffjobs = selfjobs - r(mean) if rep == 0 & selfjobs != . & year == `i'
sum selfjobs if rep == 0 & selfjobs != . & year == `i', meanonly
replace adiffjobs = selfjobs - r(mean) if rep == 1 & selfjobs != . & year == `i'

sum selfdefense if rep == 1 & selfdefense != . & year == `i', meanonly
replace adiffdefense = selfdefense - r(mean) if rep == 0 & selfdefense != . & year == `i'
sum selfdefense if rep == 0 & selfdefense != . & year == `i', meanonly
replace adiffdefense = selfdefense - r(mean) if rep == 1 & selfdefense != . & year == `i'

sum selfinsure if rep == 1 & selfinsure != . & year == `i', meanonly
replace adiffinsure = selfinsure - r(mean) if rep == 0 & selfinsure != . & year == `i'
sum selfinsure if rep == 0 & selfinsure != . & year == `i', meanonly
replace adiffinsure = selfinsure - r(mean) if rep == 1 & selfinsure != . & year == `i'
}

replace adiffideo = abs(adiffideo)
replace adiffaid = abs(adiffaid)
replace adiffjobs = abs(adiffjobs)
replace adiffdefense = abs(adiffdefense)
replace adiffservice = abs(adiffservice)
replace adiffinsure = abs(adiffinsure)
		
	
	
* Use 1972 to calibrate "partyideodiff"
factor adiffideo adiffaid adiffjobs adiffinsure ///
	if year == 1972, ipf
sem (Polarize -> adiffideo adiffaid adiffjobs adiffinsure ///
	if year == 1972)
predict apolscore1972, latent		
	
constraint 3 _b[adiffideo:Polarize] = 1
constraint 4 _b[adiffideo:_cons] = 1.227935


* 1976
factor adiffideo adiffaid adiffjobs adiffinsure ///
	if year == 1976, ipf
sem (Polarize -> adiffideo adiffaid adiffjobs adiffinsure ///
	if year == 1976), constraints(3/4) standard
predict apolscore1976, latent	


* 1978
factor adiffideo adiffaid adiffjobs adiffinsure ///
	if year == 1978, ipf
sem (Polarize -> adiffideo adiffaid adiffjobs adiffinsure ///
	if year == 1978), constraints(3/4) standard
predict apolscore1978, latent	


* 1980
factor adiffideo adiffaid adiffjobs adiffdefense  ///
	if year == 1980, ipf
sem (Polarize -> adiffideo adiffaid adiffjobs adiffdefense  ///
	if year == 1980), constraints(3/4) standard
predict apolscore1980, latent


* 1982
factor adiffideo adiffaid adiffjobs adiffdefense adiffservice ///
	if year == 1982, ipf
sem (Polarize -> adiffideo adiffaid adiffjobs adiffdefense adiffservice ///
	if year == 1982), constraints(3/4) standard
predict apolscore1982, latent


* 1984
factor adiffideo adiffaid adiffjobs adiffdefense adiffservice ///
	adiffinsure if year == 1984, ipf
sem (Polarize -> adiffideo adiffaid adiffjobs adiffdefense adiffservice ///
	adiffinsure if year == 1984), constraints(3/4) standard
predict apolscore1984, latent


* 1988
factor adiffideo adiffaid adiffjobs adiffdefense adiffservice ///
	adiffinsure if year == 1988, ipf
sem (Polarize -> adiffideo adiffaid adiffjobs adiffdefense adiffservice ///
	adiffinsure if year == 1988), constraints(3/4) standard
predict apolscore1988, latent


* 1990
factor adiffideo adiffaid adiffjobs adiffdefense adiffservice ///
	if year == 1990, ipf
sem (Polarize -> adiffideo adiffaid adiffjobs adiffdefense adiffservice ///
	if year == 1990), constraints(3/4) standard
predict apolscore1990, latent


* 1992
factor adiffideo adiffaid adiffjobs adiffdefense adiffservice ///
	adiffinsure if year == 1992, ipf
sem (Polarize -> adiffideo adiffaid adiffjobs adiffdefense adiffservice ///
	adiffinsure if year == 1992), constraints(3/4) standard
predict apolscore1992, latent


* 1994
factor adiffideo adiffaid adiffjobs adiffdefense adiffservice ///
	adiffinsure if year == 1994, ipf
sem (Polarize -> adiffideo adiffaid adiffjobs adiffdefense adiffservice ///
	adiffinsure if year == 1994), constraints(3/4) standard
predict apolscore1994, latent


* 1996
factor adiffideo adiffaid adiffjobs adiffdefense adiffservice ///
	adiffinsure if year == 1996, ipf
sem (Polarize ->  adiffideo adiffaid adiffjobs adiffdefense adiffservice ///
	adiffinsure if year == 1996), constraints(3/4) standard
predict apolscore1996, latent


* 2000
factor adiffideo adiffaid adiffjobs adiffdefense adiffservice ///
	adiffinsure if year == 2000, ipf
sem (Polarize -> adiffideo adiffaid adiffjobs adiffdefense adiffservice ///
	adiffinsure if year == 2000), constraints(3/4) standard
predict apolscore2000, latent


* 2004
factor adiffideo adiffaid adiffjobs adiffdefense adiffservice ///
	adiffinsure if year == 2004, ipf
sem (Polarize -> adiffideo adiffaid adiffjobs adiffdefense adiffservice ///
	adiffinsure if year == 2004), constraints(3/4) standard
predict apolscore2004, latent


* 2012
factor adiffideo adiffaid adiffjobs adiffdefense adiffservice ///
	adiffinsure if year == 2012, ipf
sem (Polarize -> adiffideo adiffaid adiffjobs adiffdefense adiffservice ///
	adiffinsure if year == 2012), constraints(3/4) standard
predict apolscore2012, latent


gen apolscore = .
replace apolscore = apolscore1972 if year == 1972
replace apolscore = apolscore1976 if year == 1976
replace apolscore = apolscore1978 if year == 1978
replace apolscore = apolscore1980 if year == 1980
replace apolscore = apolscore1982 if year == 1982
replace apolscore = apolscore1984 if year == 1984
replace apolscore = apolscore1988 if year == 1988
replace apolscore = apolscore1990 if year == 1990
replace apolscore = apolscore1992 if year == 1992
replace apolscore = apolscore1994 if year == 1994
replace apolscore = apolscore1996 if year == 1996
replace apolscore = apolscore2000 if year == 2000
replace apolscore = apolscore2004 if year == 2004
replace apolscore = apolscore2012 if year == 2012


* Recode variables to range 0-1

levelsof year, local(lev)	
	
foreach i of local lev {
foreach v of var ideostrength pidstrength demlike-repdislike ///
ideothermdiff partydifftherm diffcandtherm valuepol ///
adiffideo adiffaid adiffjobs adiffdefense adiffservice adiffinsure ///
ppolscore ppolscoreb apolscore edu age sophistication income housepol pid ideo ///
trust efficacy participate interest{ 
	su `v', meanonly 
	gen `v'2 = (`v' - r(min))/(r(max) - r(min)) 
}
}

********************************************************************************

*** Individual-level analyses ***

* Correlates of actual and perceived polarization
reg ppolscoreb2 ideostrength2 pidstrength2 sophistication2 ///
	edu2 age2 income2 female black hispanic south housepol2, beta
est store mod1		

reg apolscore2 ideostrength2 pidstrength2 sophistication2 ///
	edu2 age2 income2 female black hispanic south housepol2, beta
est store mod2

mvreg ppolscoreb2 apolscore2 = ideostrength2 pidstrength2 sophistication2 ///
	edu2 age2 income2 female black hispanic south housepol2

	
test [ppolscoreb2]ideostrength2 = [apolscore2]ideostrength2	
test [ppolscoreb2]pidstrength2 = [apolscore2]pidstrength2
test [ppolscoreb2]sophistication2 = [apolscore2]sophistication2
test [ppolscoreb2]edu2 = [apolscore2]edu2
test [ppolscoreb2]age2 = [apolscore2]age2
test [ppolscoreb2]income2 = [apolscore2]income2
test [ppolscoreb2]female = [apolscore2]female
test [ppolscoreb2]black = [apolscore2]black
test [ppolscoreb2]hispanic = [apolscore2]hispanic
test [ppolscoreb2]south = [apolscore2]south
test [ppolscoreb2]housepol2 = [apolscore2]housepol2
	

estout mod1 mod2, cells(b(star fmt(3)) se(par fmt(3))) ///
   legend label varlabels(_cons constant) stats(r2 N, fmt(3 0 1))


   
* Effects of polarization types on orientations toward government
regress participate2 ppolscoreb2 apolscore2 ideostrength2 pidstrength2 ///
	interest2 edu2 age2 income2 female black hispanic south i.year, beta
est store mod3 	
quietly margins, at(ppolscoreb2=(0(.1)1)) post
estimates store ppolpartic
regress participate2 ppolscoreb2 apolscore2 ideostrength2 pidstrength2 ///
	interest2 edu2 age2 income2 female black hispanic south i.year, beta
quietly margins, at(apolscore2=(0(.1)1)) post
estimates store apolpartic
coefplot ppolpartic apolpartic
	
	
logit yesvote ppolscoreb2 apolscore2 ideostrength2 pidstrength2 ///
	interest2 edu2 age2 income2 female black hispanic south i.year
est store mod4 	
quietly margins, at(ppolscoreb2=(0(.1)1)) post
estimates store ppolvote
logit yesvote ppolscoreb2 apolscore2 ideostrength2 pidstrength2 ///
	interest2 edu2 age2 income2 female black hispanic south i.year
quietly margins, at(apolscore2=(0(.1)1)) post
estimates store apolvote
coefplot ppolvote apolvote

	
regress efficacy2 ppolscoreb2 apolscore2 ideostrength2 pidstrength2 ///
	sophistication2 edu2 age2 income2 female black hispanic south i.year, beta
est store mod5 	
quietly margins, at(ppolscoreb2=(0(.1)1)) post
estimates store ppoleff
regress efficacy2 ppolscoreb2 apolscore2 ideostrength2 pidstrength2 ///
	sophistication2 edu2 age2 income2 female black hispanic south i.year, beta
quietly margins, at(apolscore2=(0(.1)1)) post
estimates store apoleff
coefplot ppoleff apoleff

	
regress trust2 ppolscoreb2 apolscore2 ideo2 pid2 ///
	sophistication2 edu2 age2 income2 female black hispanic south i.year, beta
est store mod6 		
quietly margins, at(ppolscoreb2=(0(.1)1)) post
estimates store ppoltrust
regress trust2 ppolscoreb2 apolscore2 ideo2 pid2 ///
	sophistication2 edu2 age2 income2 female black hispanic south i.year, beta		
quietly margins, at(apolscore2=(0(.1)1)) post
estimates store apoltrust
coefplot ppoltrust apoltrust


estout mod3 mod4 mod5 mod6, cells(b(star fmt(3)) se(par fmt(3))) ///
   legend label varlabels(_cons constant) stats(r2 N, fmt(3 0 1))
   
   
* Effects of polarization types on affective polarization
regress diffcandtherm2 ppolscoreb2 apolscore2 ideostrength2 pidstrength2 ///
	sophistication2 edu2 age2 income2 female black hispanic south i.year, beta
margins, at(ppolscoreb2 = (0(.01).25)) post
quietly regress diffcandtherm2 ppolscoreb2 apolscore2 ideostrength2 pidstrength2 ///
	sophistication2 edu2 age2 income2 female black hispanic south i.year, beta
margins, at(ppolscoreb2 = (.75(.01)1)) post
quietly regress diffcandtherm2 ppolscoreb2 apolscore2 ideostrength2 pidstrength2 ///
	sophistication2 edu2 age2 income2 female black hispanic south i.year, beta
margins, at(apolscore2 = (0(.01).25)) post
quietly regress diffcandtherm2 ppolscoreb2 apolscore2 ideostrength2 pidstrength2 ///
	sophistication2 edu2 age2 income2 female black hispanic south i.year, beta
margins, at(apolscore2 = (.75(.01)1)) post

	
regress partydifftherm2 ppolscoreb2 apolscore2 ideostrength2 pidstrength2 ///
	sophistication2 edu2 age2 income2 female black hispanic south i.year, beta
margins, at(ppolscoreb2 = (0(.01).25)) post
quietly regress partydifftherm2 ppolscoreb2 apolscore2 ideostrength2 pidstrength2 ///
	sophistication2 edu2 age2 income2 female black hispanic south i.year, beta
margins, at(ppolscoreb2 = (.75(.01)1)) post
quietly regress partydifftherm2 ppolscoreb2 apolscore2 ideostrength2 pidstrength2 ///
	sophistication2 edu2 age2 income2 female black hispanic south i.year, beta
margins, at(apolscore2 = (0(.01).25)) post
quietly regress partydifftherm2 ppolscoreb2 apolscore2 ideostrength2 pidstrength2 ///
	sophistication2 edu2 age2 income2 female black hispanic south i.year, beta
margins, at(apolscore2 = (.75(.01)1)) post


regress ideothermdiff2 ppolscoreb2 apolscore2 ideostrength2 pidstrength2 ///
	sophistication2 edu2 age2 income2 female black hispanic south i.year, beta
margins, at(ppolscoreb2 = (0(.01).25)) post
quietly regress ideothermdiff2 ppolscoreb2 apolscore2 ideostrength2 pidstrength2 ///
	sophistication2 edu2 age2 income2 female black hispanic south i.year, beta
margins, at(ppolscoreb2 = (.75(.01)1)) post
quietly regress ideothermdiff2 ppolscoreb2 apolscore2 ideostrength2 pidstrength2 ///
	sophistication2 edu2 age2 income2 female black hispanic south i.year, beta
margins, at(apolscore2 = (0(.01).25)) post
quietly regress ideothermdiff2 ppolscoreb2 apolscore2 ideostrength2 pidstrength2 ///
	sophistication2 edu2 age2 income2 female black hispanic south i.year, beta
margins, at(apolscore2 = (.75(.01)1)) post

	
regress ideothermdiff2 ppolscoreb2 apolscore2 ideostrength2 pidstrength2 ///
	sophistication2 edu2 age2 income2 female black hispanic south i.year, beta
est store mod9 		
quietly margins, at(ppolscoreb2=(0(.1)1)) post
estimates store ppolideo
regress ideothermdiff2 ppolscoreb2 apolscore2 ideostrength2 pidstrength2 ///
	sophistication2 edu2 age2 income2 female black hispanic south i.year, beta
quietly margins, at(apolscore2=(0(.1)1)) post
estimates store apolideo
coefplot ppolideo apolideo


estout mod7 mod8 mod9, cells(b(star fmt(3)) se(par fmt(3))) ///
   legend label varlabels(_cons constant) stats(r2 N, fmt(3 0 1))  


********************************************************************************
   
  
